public class Test19 {
    public class NKBM83 {
        public static String trams(String s,int n){
            if(n==0){
                return s;
            }
            StringBuffer s1 = new StringBuffer();
            //大小写转换
            for (int i = 0; i <n; i++) {
                if(s.charAt(i)>='A' && s.charAt(i)<='Z') {
                    s1.append((char)(s.charAt(i) - 'A' + 'a'));
                }
                else if(s.charAt(i)>='a' && s.charAt(i)<='z'){
                    s1.append((char)(s.charAt(i)-'a'+'A'));
                }
                else {
                    s1.append(s.charAt(i));
                }
            }
            //翻转
            s1=s1.reverse();
            for (int i = 0; i < n; i++) {
                int j =i;
                while(j<n && s1.charAt(j) != ' ') {
                    j++;
                }
                String temp = s1.substring(i,j);
                StringBuffer buffer = new StringBuffer(temp);
                temp=buffer.reverse().toString();
                s1.replace(i,j,temp);
                i=j;
            }
            return s1.toString();
        }

        public static void main(String[] args) {
            String s = "hello world";
            int n =s.length();
            System.out.println(trams(s,n));
        }

    }



}
